package com.study.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author wanghao
 * @version v1.0
 * @description: 演示线程池的三种分类
 * @date 2022/1/5 13:47
 * @change [修改时间] [修改者]@[版本号] [修改内容说明]
 */
public class ThreadPoolDemo01 {

    public static void main(String[] args) {

        // 一池五线程
        ExecutorService threadPool1 = Executors.newFixedThreadPool(5);

        // 一池一线程
        ExecutorService threadPool2 = Executors.newSingleThreadExecutor();

        // 一池可扩容线程
        ExecutorService threadPool3 = Executors.newCachedThreadPool();

        try {
            for (int i = 0; i < 10; i++) {
                // 执行
                threadPool3.execute(()->{
                    System.out.println(Thread.currentThread().getName()+" 办理业务");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 关闭
            threadPool3.shutdown();
        }
    }
}
